package com.hundsun.yr.universal.p2p.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hundsun.mobile.zwgt.R;

/**
 * @Title: ItemView.java 
 * @Description: 带箭头的列表item控件
 * @date 2016-1-28 下午7:40:57 
 * @author:tonglj
 * @email:
 * @replace author: hejun.shen
 * @replace date: 2016-1-28 
 * @replace: 添加了hint方法和回收TypedArray
 * @version V1.0   
 */
public class ItemView extends LinearLayout implements OnClickListener{
	private LinearLayout expandView;
	private TextView valueText,titleText;
	/**
	 * 真实值 用于后台保存数据
	 */
	private String realValue;
	

	public ItemView(Context context) {
		this(context,null);
	}

	public ItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context,attrs);
	}
	
	public void addView(View view){
		expandView.addView(view);
	}
	

	public String getRealValue() {
		return realValue;
	}

	public void setRealValue(String realValue) {
		this.realValue = realValue;
	}

	private void init(Context context, AttributeSet attrs){
		setOrientation(LinearLayout.HORIZONTAL);
		View.inflate(context, R.layout.item_view, this);
		expandView = (LinearLayout)findViewById(R.id.item_view_content);
		valueText = (TextView)findViewById(R.id.item_view_value);
		titleText = (TextView)findViewById(R.id.item_view_name);
		ImageView icon = (ImageView)findViewById(R.id.skip_icon);
		TypedArray  typearr = context.obtainStyledAttributes(attrs, R.styleable.ItemView);
		int hintId = typearr.getResourceId(R.styleable.ItemView_hint, R.string.empty);
		setHint(hintId);
		int nameId = typearr.getResourceId(R.styleable.ItemView_name, R.string.empty);
		setName(nameId);
		int valId = typearr.getResourceId(R.styleable.ItemView_value, R.string.empty);
		setValue(valId);
		if(typearr.hasValue(R.styleable.ItemView_hide_skip)){
			boolean showFlag = typearr.getBoolean(R.styleable.ItemView_hide_skip, false);
			if(showFlag){
				icon.setVisibility(View.GONE);
			}
		}
		typearr.recycle();
	}
	
	public void setHint(int resid){
		valueText.setHint(resid);
	}
	
	/**
	 * 设置隐藏内容
	 * @param hint 隐藏文本
	 */
	public void setHint(String hint){
		valueText.setHint(hint);
	}
	
	public void setValue(int resid){
		valueText.setText(resid);
	}
	
	public void setValue(String value){
		if(TextUtils.isEmpty(realValue)){
			realValue = value;
		}
		valueText.setText(value);
	}
	
	public String getValue(){
		return valueText.getText().toString();
	}
	
	public void setName(int resid){
		titleText.setText(resid);
	}

	
	public void setName(String title){
		titleText.setText(title);
	}
	@Override
	public void onClick(View v) {
		if(v==this){
			
		}
		
	}
	
//	puclic inf
}
